<?php
require_once (APPLICATION_DIR."/application/model/Topmenu.php");
class Topmenu extends DataObjects_Topmenu
{	
	function getMenuTitle()
	{
		$this->selectAdd();
		$this->selectAdd("menu_id,menu_url,menu_title");
		$this->orderBy("menu_id");
		$this->find();
		return $this;
	}
	
	function prepareTopMenu()
	{
		$smarty 	= DRX::load("smarty");
		
    	$submenu	= new Submenu();
    	$submenu->prepareDropMenu(ABOUT_ID,ABOUT_URL . NODE_CONTENT_ACTION);

		$submenu	= new Submenu();
    	$submenu->prepareDropMenu(PROGRAMME_ID,PROGRAMME_URL . NODE_CONTENT_ACTION);
    	
    	$partner	= new Partner();
    	$partner->prepareDropMenu(PARTNER_ID,PARTNER_URL . NODE_CONTENT_ACTION);
    	
    	$admission_dropmenu = $smarty->fetch("admission/dropmenu.tpl");
        $smarty->assign("dropmenu". ADMISSION_ID,$admission_dropmenu);
    	
    	$submenu	= new Submenu();
    	$submenu->prepareDropMenu(PARTNER_ID,PARTNER_URL . NODE_CONTENT_ACTION);
        
        $link = new Link();
    	$linkList = $link->getAllLink();
    	$smarty->assign("linkList",$linkList);
    	$student_dropmenu = $smarty->fetch("student/dropmenu.tpl");
        $smarty->assign("dropmenu". STUDENT_ID,$student_dropmenu);
        
	}
	
	function getTopBannerURL($top_banner)
	{
	    $list = explode("/",$top_banner);
        $filename = $list[count($list)-1];
        $url = TOPMENU_BANNER_URL . "$filename";
        return $url;
	}
	
	function prepareTopBanner($top_id)
	{
	    $smarty 	= DRX::load("smarty");
		
	    $this->menu_id = $top_id;
	    $this->selectAdd();
	    $this->selectAdd("menu_banner");
	    $this->find();
	    if ($this->fetch())
	    {
	        $top_banner = $this->menu_banner;
	        if ($top_banner)
	        {
	            $top_banner = $this->getTopBannerURL($top_banner);
	        }
	    }
		$smarty->assign("top_banner",$top_banner);
	}
	
	function getTopUrl($menu_id)
	{
		$this->selectAdd();
		$this->selectAdd("menu_url");
		$this->whereAdd();
		$this->whereAdd("menu_id = $menu_id");
		$this->find();
		if ($this->fetch())
		{
			$result = $this->menu_url;
		}
		else 
		{
			$result = "";
		}
		return $result;
	}
	
	function getTopPageContent($menu_id)
	{
		$this->selectAdd();
		$this->selectAdd("menu_node_id");
		$this->whereAdd();
		$this->whereAdd("menu_id = $menu_id");
		$this->find();
		$this->fetch();
		$node_id 	= $this->menu_node_id;
		$node 		= new Node();
		$result 	= $node->getNodeInfo($node_id);
		return $result;
	}
	
	function updateBanner($menu_id,$menu_banner)
	{
	    $this->menu_id = $menu_id;
	    $this->menu_banner = $menu_banner;
	    $this->update();
	}
}
?>